package com.boatAnchorAssistant.service.controller.app;

import com.boatAnchorAssistant.pojo.param.notice.*;
import com.boatAnchorAssistant.pojo.vo.notice.*;
import com.boatAnchorAssistant.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.List;

/**
 * app/通知
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/notice/app")
public class NoticeAppController {

    private final NoticeService service;

    public NoticeAppController(NoticeService service) {
        this.service = service;
    }


    /**
     * 创建通知
     *
     * @param param
     * @return
     */
    @PostMapping("/createNotice")
    public ApiResult createNotice(@RequestBody @Valid CreateNoticeParam param) {
        service.createNotice(param);
        return ApiResult.ok();
    }


    /**
     * 修改通知
     *
     * @param param
     */
    @PutMapping("/editNotice")
    public ApiResult editNotice(@RequestBody @Valid EditNoticeParam param) {
        service.editNotice(param);
        return ApiResult.ok();
    }

    /**
     * 移除通知
     *
     * @param id
     */
    @DeleteMapping("/removeNotice")
    public ApiResult removeNotice(@RequestParam("id") Long id) {
        service.removeNotice(id);
        return ApiResult.ok();
    }

    /**
     * 获取最近的一条通知
     *
     * @return
     */
    @GetMapping("/selectOneNotice")
    public ApiResult<GetNoticeVo> selectOneNotice() {
        GetNoticeVo vo = service.selectOneNotice();
        return ApiResult.ok(vo);
    }

    /**
     * 获取通知详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getNotice")
    public ApiResult<GetNoticeVo> getNotice(@RequestParam("id") Long id) {
        GetNoticeVo vo = service.getNotice(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取通知列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getNoticeList")
    public ApiResult<PageResult<GetNoticeListVo>> getNoticeList(@RequestBody GetNoticeListParam param) {
        PageResult<GetNoticeListVo> result = service.getNoticeList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取通知下拉列表
     *
     * @return
     */
    @PostMapping("/getNoticeDownList")
    public ApiResult<List<GetNoticeDownListVo>> getNoticeDownList(@RequestBody(required = false) @Valid GetNoticeDownListParam param) {
        List<GetNoticeDownListVo> list = service.getNoticeDownList(param);
        return ApiResult.ok(list);
    }


}

